<?php

 /**
  * @package JooS_Syntax
  */

  require_once "JooS/Syntax/Abstract.php";

  class JooS_Syntax_Except extends JooS_Syntax_Abstract {
    /**
     * @var JooS_Syntax_Abstract $trueRule
     */
    private $_trueRule = null;
    
    /**
     * @var JooS_Syntax_Abstract $trueRule
     */
    private $_falseRule = null;

    /**
     * @param JooS_Syntax_Abstract $trueRule
     */
    private function setTrueRule(JooS_Syntax_Abstract $trueRule) {
      $this->_trueRule = $trueRule;
    }

    /**
     * @param JooS_Syntax_Abstract $falseRule
     */
    private function setFalseRule(JooS_Syntax_Abstract $falseRule) {
      $this->_falseRule = $falseRule;
    }

    public function init() {
      $this->setTrueRule(func_get_arg(0));
      $this->setFalseRule(func_get_arg(1));
    }

    /**
     * @return string
     */
    public function compile() {
      $exprPos = $this->getParser()->getPos();

      if ($this->_falseRule->compileSyntax() !== false) {
        $this->getParser()->setPos($exprPos);
        return false;
      }
      return $this->_trueRule->compileSyntax();
    }
  }
